﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSTK04
    {
        #region ==dwKEY===========
        public static readonly DependencyProperty dwKEYProperty = DependencyProperty.Register("dwKEY",
            typeof(DataRowView), typeof(TSTK04),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwKEYChanged));
        public DataRowView dwKEY
        {
            get
            {
                return (DataRowView)GetValue(dwKEYProperty);
            }
            set
            {
                SetValue(dwKEYProperty, value);
            }
        }
        private static void OndwKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSTK04;
            if (src != null)
            {
                src.dwKEY = (DataRowView)e.NewValue;
                src.Load();
            }
        }
        #endregion
        #region ==dwSTOCK===========
        public static readonly DependencyProperty dwSTOCKProperty = DependencyProperty.Register("dwSTOCK",
            typeof(DataRowView), typeof(TSTK04),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwSTOCKChanged));
        public DataRowView dwSTOCK
        {
            get
            {
                return (DataRowView)GetValue(dwSTOCKProperty);
            }
            set
            {
                SetValue(dwSTOCKProperty, value);
            }
        }
        private static void OndwSTOCKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSTK04;
            if (src != null)
            {
                src.dwSTOCK = (DataRowView)e.NewValue; 
            }
        }
        #endregion 
        public TSTK04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_STOCK();
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        DataRowView LastdwKEY = null;
        public void Load()
        {
            if (LastdwKEY == dwKEY)
                return;
            LastdwKEY = dwKEY;
            if (dwKEY == null)
                return;
            DataSet SResult = ((VICC_STOCK)MV).LoadMonthStock(dwKEY.Row);
            MergeData(SResult);
        }
    }
}
